﻿using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework;
using BlockeyEssentials;

namespace Blockey.GameObjects3D
{
    public class Puck3D : Moveable3D
    {
        public Puck3D(GraphicsDevice oGraphics, ContentManager oManager)
        {
            m_oDrawable = new DrawableModel(oGraphics, oManager, "Models\\Puck\\Puck", true);

            _Radius = 0.5f;
            _Friction *= 0.075f;
            _Position = new Vector3(20, 0, 0);
            _GravityPower = 0.0175f;
            _Magnitude = 0.025f;
            _ReactToCollision = false;

            m_oDrawable.SetTransformation(new Vector3(20, 0, 0), null, 6);
        }

        public void Draw(GraphicsDevice oGraphics, Camera3D oCamera)
        {
            //DebugShapeRenderer.AddLine(Position, new Vector3(Position.X, Position.Y, 0), Color.Red, 2);

            m_oDrawable.SetTransformation(Position, null, null);
            m_oDrawable.Draw(oGraphics, oCamera);

            if (DebugShapeRenderer.ShowLines)
            {
                foreach (var oSphere in Spheres)
                {
                    DebugShapeRenderer.AddBoundingSphere(oSphere, Color.Blue);
                }
            }
        }

        public override void DrawShadows(GraphicsDevice oGraphics, Camera3D oCamera)
        {
            if (_Shadow == null)
            {
                _Shadow = new DrawableCustom(oGraphics, All.Texture_Circle, false);
                _Shadow.SetTransformation(null, null, Radius);
                SetShadow();
            }

            var oPercent = 1 - (PositionZ * 0.0025f);
            _Shadow.SetTransformation(_Position * new Vector3(1, 1, 0) + Vector3.UnitZ * 0.05f, null, Radius * (oPercent));
            oPercent = 1 - (PositionZ * 0.01f);
            _Shadow.Draw(oGraphics, oCamera);
        }

        public DrawableModel Drawable
        {
            get { return m_oDrawable; }
        }

        private DrawableModel m_oDrawable;

    }
}
